package com.xr.sy.modules.demo.controller;

import lombok.Data;

@Data
public class ThreadDemo implements Runnable {
    volatile private int count = 0;

    private void add(){
        for (int i = 0; i < 1000; i++) {
            count++;
            System.out.println("count = " + count);
            try {
                Thread.sleep(20);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    @Override
    public void run() {
        add();
    }


    public static void main(String[] args) {


        ThreadDemo demo = new ThreadDemo();
        Thread t1 = new Thread(demo);
        Thread t2 = new Thread(demo);
        Thread t3 = new Thread(demo);

        t1.start();
        t2.start();
        t3.start();

    }

}
